package com.atguigu.algorithm;

import java.util.ArrayList;
import java.util.List;

public class PrintAllSub {
    public static void function(String str){
        char[] chars=str.toCharArray();
        process(chars,0,new ArrayList<>());
    }
    public static void process(char[] chars, int i, List<Character> list){
        if(i==chars.length){
            print(list);
            return;
        }else{
            List<Character> resKeep=copyList(list);
            resKeep.add(chars[i]);
            process(chars,i+1,resKeep); //要当前字符的路
            List<Character> resNoInclude=copyList(list);
            process(chars,i+1,resNoInclude); //不要当前字符的路
        }
    }

    public static void main(String[] args) {
        function("abc");
    }
    public static void print(List<Character> list){
        while(!list.isEmpty()){
            System.out.print(list.remove(0)+" ");
        }
        System.out.println();
    }
    public static List<Character> copyList(List<Character> list){
        ArrayList<Character> res=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            res.add(list.get(i));
        }
        return res;
    }
}
